﻿ // <copyright file="ReflectorTest.cs" company="Recipe Database">
//     Copyright (c) Recipe Database. All rights reserved.
// </copyright>
// <author>Bjarke Meier</author>
//-----------------------------------------------------------------------

namespace Core.Test
{
  using System;
  using Microsoft.VisualStudio.TestTools.UnitTesting;

  /// <summary>
  /// This is a test class for ReflectorTest and is intended
  /// to contain all ReflectorTest Unit Tests
  /// </summary>
  [TestClass]
  public class ReflectorTest
  {
    /// <summary>
    /// Tests <code>Reflector.GetVariableName</code>.
    /// </summary>
    [TestMethod]
    public void GetVariableNameTest()
    {
// ReSharper disable ConvertToConstant.Local
      // Do not convert to const string because it will turn the variable into a const expresssion
      var expected = "expected";

// ReSharper restore ConvertToConstant.Local
      var actual = Reflector.GetVariableName(() => expected);
      Assert.AreEqual(expected, actual);
    }

    /// <summary>
    /// Tests <code>Reflector.GetParameterName</code>.
    /// </summary>
    [TestMethod]
    public void GetParameterNameTest()
    {
      Func<string, string> f = foo => Reflector.GetParameterName(() => foo);
      const string Expected = "foo";
      var actual = f("something");
      Assert.AreEqual(Expected, actual);
    }

    /// <summary>
    /// Tests <code>Reflector.GetVariableName</code>.
    /// </summary>
    [ExpectedException(typeof(ArgumentException))]
    [TestMethod]
    public void GetVariableNameTest1()
    {
      const string C = "foo";

      // This will fail because c is not a variable but a constant.
      Reflector.GetVariableName(() => C);
    }
  }
}